<template>
<h1>注册页面</h1>
  <input type="text" placeholder="用户名" v-model="user.username">
  <input type="text" placeholder="密码" v-model="user.password">
  <input type="text" placeholder="昵称" v-model="user.nickname">
  <input type="button" value="注册" @click="reg()">
</template>

<script setup>
import axios from 'axios'
import {ref} from "vue";
import router from "@/router";
const user = ref({username:"",password:"",nickname:""})
const reg = ()=>{
  //发出注册请求
  axios.post('http://localhost:8080/v1/users/reg',user.value)
      .then((response)=>{
        //服务器响应后执行
        if(response.data.code==1){
          alert("注册成功！");
          router.push('/')
        }else{
          alert(response.data.msg);
        }
      })
}
</script>

<style scoped>

</style>